/*
 * @Author: Huangdong
 * @Date: 2022-03-30 13:59:43
 * @LastEditors: minsheng_insurance_agency_zhoucl
 * @LastEditTime: 2025-07-08 11:33:20
 * @FilePath: \01.latest-short-insure\src\store\modules\infoReg.js
 * @Description:
 *
 *
 */

import { getBirthDate, getDay } from "@/methods/date.js";

const state = {
  inputReg: {
    applicant: {
      IMPARTCOUNT: 1,
      IMPARTS: "",
      name: "",
      idType: "",
      idName: "",
      idNum: "",
      validDate: "",
      validDateEnd: "",
      sex: "",
      birthDate: "",
      nationality: "",
      nationalityName: "",
      phone: "",
      email: "",
      occupationCode: "",
      occupationCodeName: "",
      occupationClass: "",
      socialInsuFlag: "",
      maritalStatus: "",
      maritalStatusName: "",
      degree: "",
      areaName: "",
      permanentAddress: "",
      province: "",
      height: "",
      weight: "",
      city: "",
      county: "",
      zipCode: "",
      crsIdTypeName: "",
      printPolType: "",
      position: "",
    },
    insured: {
      IMPARTCOUNT: 1,
      relationToAppnt: "",
      relationToAppntName: "",
      name: "",
      idType: "",
      idName: "",
      idNum: "",
      validDate: "",
      validDateEnd: "",
      sex: "",
      birthDate: "",
      occupationCode: "",
      occupationCodeName: "",
      occupationClass: "",
      socialInsuFlag: "",
      phone: "",
      degree: "",
      nationality: "",
      nationalityName: "",
      position: "",
      areaName: "",
      height: "",
      weight: "",
      permanentAddress: "",
      crsIdTypeName: "",
      province: "",
      city: "",
      county: "",
      maritalStatus: "",
      maritalStatusName: "",
      email: "",
      zipCode: "",
      relationsWithMain: "",
    },
    benefitModel: {
      isSame: "0",
      relationToInsured: "",
      relationToInsuredName: "",
      name: "",
      idType: "",
      idName: "",
      idNum: "",
      validDate: "",
      validDateEnd: "",
      occupationCode: "",
      occupationCodeName: "",
      occupationClass: "",
      sex: "",
      birthDate: "",
      height: "",
      weight: "",
      phone: "",
      areaName: "",
      permanentAddress: "",
      province: "",
      city: "",
      county: "",
      nationality: "",
      nationalityName: "",
      bnfType: "",
      bnfTypeName: "",
      addressTypeNo: "",
      addressTypeNoName: "",
      beneficialOrder: 1,
      beneficialRate: "",
      type: 1,
    },
    payInfo: {
      payMode: "",
      transrNo: "",
      printPolType: "",
      totalPrem: "",
      bankCode: "",
      bankName: "",
      bankAccName: "",
      bankAccNo: "",
      firBankMobile: "",
      bankProvince: "",
      bankCity: "",
      bankCounty: "",
      bankArea: "",
      bankCardType: "",
      autoPayFlag: "",
      aliveGetMode: "",
      bnfBankAccName: "",
      bnfBankCode: "",
      bnfBankAccNo: "",
      expayMode: "",
    },
  },
  ageRange: {
    insured: {
      minAge: 30,
      maxAge: 1,
      isDate: true,
      // "sexFixed": "1", // 性别限制
    },
    applicant: {
      minAge: 16,
      maxAge: 70,
      isDate: false,
    },
  },

  insuYear: {
    // 保险有效期设置
    // "minDate": "1",
    // "maxDate": "30",
    // "gutterYear": 1,
    // "showEnd": "1"
  },
};

const getters = {
  ageRange: (state) => state.ageRange,
  inputReg: (state) => state.inputReg,
  insuYear: (state) => state.insuYear,
  tbBirthMin: (state) => {
    let starDate = new Date();
    if (state.ageRange.insured) {
      starDate = getBirthDate(state.ageRange.applicant.maxAge);
    }
    return starDate;
  },
  tbBirthMax: (state) => {
    let starDate = new Date();
    if (state.ageRange.insured) {
      starDate = getBirthDate(state.ageRange.applicant.minAge);
    }
    return starDate;
  },
  bbBirthMin: (state) => {
    let starDate = new Date();
    if (state.ageRange.insured) {
      starDate = getBirthDate(state.ageRange.insured.maxAge);
    }
    return starDate;
  },
  bbBirthMax: (state) => {
    let starDate = new Date();
    if (state.ageRange.insured) {
      starDate = getBirthDate(state.ageRange.insured.minAge);
      if (state.ageRange.insured.isDate) {
        starDate = getDay(-state.ageRange.insured.minAge);
      }
    }
    return starDate;
  },
};

const mutations = {
  SET_INFO_DATA(state, payload) {
    Object.assign(state, payload);
  },
};
const actions = {
  initDicStore(ctx, data) {
    // console.log("initDicStore",data)
    const keyArr = ["relationship","idTypeList"],
      len = keyArr.length;
    for (let i = 0; i < len; i++) {
      const key = keyArr[i];
      if (data.hasOwnProperty(key)) {
        let obj = {};
        obj[key] = data[key];
        ctx.dispatch("dictionary/initDictionaryCode", obj, {
          root: true,
        });
      }
    }
  },
};

export default {
  namespaced: true,
  state,
  getters,
  mutations,
  actions,
};
